package com.daiziru.im.handle;


import com.daiziru.common.constant.Constants;
import com.daiziru.im.handle.impl.ChatMsgHandler;
import com.daiziru.im.handle.impl.PingMsgHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;


/**
 * 定义消息的类型
 */
@Slf4j
public class MsgHandlerFactory {

    private static Map<String, MsgHandler> handlerMap  = new HashMap<>();

    public static void init() {
        handlerMap.put(Constants.IM_MESS_TYPE_CHAT,new ChatMsgHandler());
        handlerMap.put(Constants.IM_MESS_TYPE_PING, new PingMsgHandler());
        log.info("handle Factory inti success!");
    }

    //根据类型获取对应的handle
    public static MsgHandler getMsgHandler(String type) {
        return handlerMap.get(type);
    }
}
